package Classes.GameDatas
{
	import Classes.GameUtils.GU_DataTransform;
	import Classes.GameViews.ViewIcons.ViewIcon;
	import Classes.Managers.M_ConfigData;
	
	import UIComponents.IStore;
	import UIComponents.IUseItem;
	
	import flash.display.DisplayObject;

	/**
	 * 武器类 
	 * @author Administrator
	 */	
	public class GD_Weapon extends GameData implements IStore,IUseItem
	{
		/**
		 *默认武器 
		 */
		public static var defaultWeapon:uint;
		public static var _itemConfigDatasObj:Object;
		public var _singleWeaponItem:Object;
		
		public var weaponId:Number;
		private var _itemNumber:Number;
		
		private var _icon:ViewIcon;
		
		public function GD_Weapon(_weaponId:Number=0,_weaponNum:Number=0)
		{
			this.weaponId=_weaponId;
			this.itemNumber=_weaponNum;
			initData();
		}
		
		/**
		 * 创建一个GD_Weapon 
		 * @param creatObj  建筑类型
		 * @return 
		 */		
		public static function creat(creatObj:Object):GD_Weapon
		{
			var returnObj:GD_Weapon=new GD_Weapon(creatObj.itemType,creatObj.itemNum);
			return returnObj;
		}
		
		public static function getWeaponInfoById(weaponId:Number):Object
		{
			return itemConfigDatasObj[weaponId]
		}
		
		private function initData():void
		{
			this._singleWeaponItem=itemConfigDatasObj[this.weaponId];
		}
		
		/*getter & setter*/
		public static function get itemConfigDatasObj():Object
		{
			if(!_itemConfigDatasObj)
			{
				_itemConfigDatasObj=new Object;
				var itemConfigDatasStr:String=M_ConfigData.instance.getCSVByName("武器配置表");
				var itemConfigDatasAry:Array=GU_DataTransform.csvTransformObjsAry(itemConfigDatasStr,15);
				for each(var itemConfigDataObj:Object in itemConfigDatasAry)
				{
					_itemConfigDatasObj[itemConfigDataObj.zt_weapon_id]=itemConfigDataObj;
				}
			}
			return _itemConfigDatasObj;
		}
		
		public function creatTmpIcon():ViewIcon
		{
			return ViewIcon.creat({sourceName:this.sourceName,picName:this.picName});
		}
		
		/**
		 * 武器攻击范围 
		 * @return 
		 */		
		public function get weaponRange():int
		{
			return this._singleWeaponItem.zt_weapon_range;
		}
		
		/**
		 * 武器攻击方式    远程攻击动作	1    ；投掷攻击动作	2   ； 近战攻击动作	3
		 * @return 
		 */		
		public function get weaponAttack():int
		{
			return this._singleWeaponItem.zt_weapon_attack;
		}
		
		public function get sourceName():String
		{
			return this._singleWeaponItem.zt_item_source;
		}
		
		public function get picName():String
		{
			return this._singleWeaponItem.zt_weapon_pic;
		}
		
		/**
		 * 武器名字 --实现商店接口
		 * @return 
		 * 
		 */		
		public function getStoreItemName():String
		{
			return this._singleWeaponItem.zt_weapon_name;
		}
		/**
		 * 武器图片  --实现商店接口
		 * @return 
		 * 
		 */		
		public function getStoreItemIcon():DisplayObject
		{
			return creatTmpIcon();
		}
		
		public function getStoreItmePic():String
		{
			return this._singleWeaponItem.zt_weapon_pic;
		}
		
		/**
		 * 武器描述  --实现商店接口
		 * @return 
		 */		
		public function getStroeItemDes():String
		{
			return this._singleWeaponItem.zt_weapon_desc;
		}
		
		public function get itemPic():DisplayObject
		{
			return this.icon
		}
		
		public function get itemName():String
		{
			return  this._singleWeaponItem.zt_weapon_name;
		}
		
		public function get useEnabled():Boolean
		{
			return true;
		}
		
		public function get description():String
		{
			return this._singleWeaponItem.zt_weapon_desc;
		}
		
		/**
		 * 控制使用按钮是否显示 
		 */
		public function get useBtnVisiable():Boolean
		{
			return true;
		}
		
		public function useItem():void
		{
		}
		
		public function doSomeThingFun(shopId:Number,itemPrice:Number,moneyType:Number,isDoing:Boolean=true):void{}
		
		public function get itemNumber():Number
		{
			return _itemNumber;
		}

		public function set itemNumber(value:Number):void
		{
			_itemNumber = value;
			this.touchObserve("itemNumber");
		}
		
		public function get icon():ViewIcon
		{
//			if(!_icon)
//			{
				_icon=ViewIcon.creat({dataTarget:this,creatType:"item"});
				_icon.numSP.x=56;
				_icon.numSP.y=20;
				_icon.scaleX=0.5;
				_icon.scaleY=0.5;
				_icon.type	=	this.itemId==defaultWeapon?2:1;
//			}
			return _icon;
		}
		
		public function get itemId():Number
		{
			return this.weaponId;
		}
	}
}